package com.mycompany.app.hr.security.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import com.mycompany.app.common.audit.modification.model.AuditEmbeddedObject;

@SuppressWarnings("unchecked")
@Entity
@Table(name = "s_user")
public class SystemUser {

    @Id
    @Column(name = "user_id")
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Column(name = "login_name")
    private String loginName;

    @Column(name = "name")
    private String name;

    @Column(name = "password")
    private String password;

    @Column(name = "description")
    private String description;

    @Column(name = "email")
    private String email;

    @Column(name = "is_active", nullable = true)
    private Boolean isActive;

    @ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER,mappedBy="users")
    //@JoinTable(name = "s_user_role", joinColumns = { @JoinColumn(name = "user_id") }, inverseJoinColumns = { @JoinColumn(name = "role_id") })
    private Set<SystemRole> roles = new HashSet<SystemRole>(0);

    @Embedded
    private AuditEmbeddedObject auditEmbeddedObject = new AuditEmbeddedObject();

    // ===================================

    @Override
    public String toString() {

        return ToStringBuilder.reflectionToString(this,
                ToStringStyle.SHORT_PREFIX_STYLE);
    }

    // ===================================

    public Long getId() {

        return id;
    }

    public void setId(Long id) {

        this.id = id;
    }

    public String getLoginName() {

        return loginName;
    }

    public void setLoginName(String loginName) {

        this.loginName = loginName;
    }

    public String getName() {

        return name;
    }

    public void setName(String name) {

        this.name = name;
    }

    public String getPassword() {

        return password;
    }

    public void setPassword(String password) {

        this.password = password;
    }

    public String getDescription() {

        return description;
    }

    public void setDescription(String description) {

        this.description = description;
    }

    public String getEmail() {

        return email;
    }

    public void setEmail(String email) {

        this.email = email;
    }

    public boolean isActive() {

        return isActive;
    }

    public void setActive(Boolean isActive) {

        this.isActive = isActive;
    }

    public AuditEmbeddedObject getAuditEmbeddedObject() {

        return auditEmbeddedObject;
    }

    public void setAuditEmbeddedObject(AuditEmbeddedObject auditEmbeddedObject) {

        this.auditEmbeddedObject = auditEmbeddedObject;
    }

    public Boolean getIsActive() {

        return isActive;
    }

    public void setIsActive(Boolean isActive) {

        this.isActive = isActive;
    }

    public Set<SystemRole> getRoles() {

        return roles;
    }

    public void setRoles(Set<SystemRole> roles) {

        this.roles = roles;
    }

}
